<?php
//App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF();
//$tcpdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$textfont = 'helvetica';
 
//$tcpdf->SetAuthor("bachpt");
//$tcpdf->SetAutoPageBreak(true);

$tcpdf->setHeaderFont(array($textfont,'',20)); 
$tcpdf->xheadercolor = array(150,0,0); 
$tcpdf->xheadertext = 'Subscribers Report'; 
$tcpdf->xfootertext = 'Beaconschool. All rights reserved.'; 
 
$tcpdf->setPrintHeader(true);
$tcpdf->setPrintFooter(true);

// set default monospaced font
$tcpdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$tcpdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',7);
 
$tcpdf->AddPage();

	$htmlcontent = "<h2>{$subscribers[0]['School']['schoolName']} Subscribers Report</h2>";
	$htmlcontent .= '<table border="0" cellpadding="1" cellspacing="0" width="100%">
						<tr style="color: #1F4DAF; font-weight: bold;">
							<td>Username</td>
							<td>Firstname</td>
							<td>Lastname</td>
							<td>Mobile</td>
							<td>Email</td>
							<td>User Status</td>
						</tr>
					</table>	
					';
			
$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
			
	foreach ($subscribers as $subscriber) {	
		$status = $subscriber['User']['active']==1?'Active':'Inactive';
		
		$htmlRow = <<<EOD
					<table>
						<tr>
							<td>{$subscriber['User']['userName']}</td>
							<td>{$subscriber['Subscriber']['firstName']}</td>
							<td>{$subscriber['Subscriber']['lastName']}</td>
							<td>{$phone->format_phone($subscriber['Contact']['phone'])}</td>
							<td>{$subscriber['Contact']['email']}</td>
							<td align=\"center\">{$status}</td>
						</tr>
					</table>
EOD;
$tcpdf->writeHTML($htmlRow, true, 0, true, 0);
}

$tcpdf->Output('subscribers.pdf', 'D');
?>